﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.EShop.Bll;
using Runda.EShop.Common.Utility;
using Runda.EShop.Common.Entity;

namespace Runda.EShop.SaaS.SysManage
{
    public partial class RoleList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lnkbtnAddRole.Attributes.Add("onclick", "return OnRoleAdd('RoleAdd.aspx');");
            if (!IsPostBack)
            {
                BindGrid(ConstHelper.PAGE_INIT_INDEX);
            }
        }


        protected void btnQuery_Click(object sender, EventArgs e)
        {
            BindGrid(ConstHelper.PAGE_INIT_INDEX);
        }

        private void BindGrid(int PageIndex)
        {
            SystemBll bll = new SystemBll();

            List<SqlDbParameter> parms = new List<SqlDbParameter>();
            SqlDbParameter parm = null;

            int RecordCount = 0;
            List<SysRoleEntity> list = bll.GetAll<SysRoleEntity>(parms, "CreatedOn desc", AspNetPager1.PageSize, PageIndex, out RecordCount);
            gvRoleList.DataSource = list;
            gvRoleList.DataBind();
            AspNetPager1.RecordCount = RecordCount;
             
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindGrid(AspNetPager1.CurrentPageIndex - 1);
        } 

        protected void gvRoleList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Guid RoleID = new Guid(gvRoleList.DataKeys[e.RowIndex]["RoleID"].ToString());
            SystemBll bll = new SystemBll();
            bll.DeleteRole(RoleID);
            BindGrid(ConstHelper.PAGE_INIT_INDEX);

            DoOperationLog(EnumHelper.OperationType.Delete, "删除角色，ID:" + RoleID);
        }

       
    }
}